import time

import requests
def poseSongList(songList):
    # 上传歌曲名列表到服务器，获取可以用的标题
    STATUES = True
    while STATUES:

        # url = 'http://118.24.22.205/messageBox/sendMakeMovieSongList/'
        url = 'http://127.0.0.1:8000/messageBox/sendMakeMovieSongList/'
        data = {
            'data': songList
        }
        html = requests.post(url, json=data,timeout=7000)
        print(html.json())
        if html.json()['data'] =='nonew':
            print("服务器复用库没有新内容了，请及时添加,重新加载...")
            time.sleep(5)
        elif html.json()['data'] =='error':
            print("客户端数据错误,重新加载...")
            time.sleep(5)
        else:
            STATUES =False

    return html.json()['data']  # 得到标题内容

def postHasUsed(title):  #把已经使用过的title 发给服务器reused表做记录
    url = 'http://127.0.0.1:8000/messageBox/sendMakeMovieSongListHasUsed/'
    data = {
        'data': [title]
    }
    html = requests.post(url, json=data)
    print(html.json())
def postSongListToSongJson(uploadSongList):
    url = f'http://127.0.0.1:8000/messageBox/savesongs/'
    data = {'data': uploadSongList}
    html = requests.post(url, json=data)
    print(html.json())
if __name__ == '__main__':
    # # 1-----请求获得新标题使用方法
    songList = ['wd', '烦烦烦']
    getOkTitle = poseSongList(songList)

    # #2-----已经使用，上报标题
    # postHasUsed(getOkTitle)

    # postSongListToSongJson(songList)